/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.crystalcg.log;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author lifeng
 */
public class Log {

    public static final int MAX_BUFFER=4096;
    private static File file;
    public static void log(String str){
        Date date=new Date();
        SimpleDateFormat dfFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy_MM_dd");
        file=new File("stock_log_"+dateFormat.format(date)+".txt");
        try {
            if(!file.exists()){
                file.createNewFile();
            }
            FileWriter fileWriter=new FileWriter(file,true);
            fileWriter.write("*log: "+str+"  time:["+dfFormat.format(date)+"]\r\n\r\n");
            System.out.println("*log: "+str+"  time:["+dfFormat.format(date)+"]");
            fileWriter.close();
            //FileInputStream inputStream=new FileInputStream(file);
            //FileOutputStream outputStream =new FileOutputStream(file);
            //FileChannel fileChannel=outputStream.getChannel();
            //ByteBuffer buffer=ByteBuffer.allocate(MAX_BUFFER);
            //buffer.clear();
            //outputStream.flush();
            
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
